package com.chujian.Activities;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.chujian.Adapter.BookListAdapter;
import com.chujian.Threads.HttpClientPostThread;
import com.chujian.Utils.Constan;
import com.chujian.Utils.JsonUtil;
import com.chujian.model.Book;
import com.chujian.orderingsystem.R;
import com.google.gson.Gson;

public class BookListSellerActivity extends Activity implements OnItemClickListener{
	private ListView mListView;
	private BookListAdapter mAdapter;
	private List<Book>mList;
	private Handler mHandler=new Handler(){
		public void handleMessage(android.os.Message msg) {
			super.handleMessage(msg);
			String str=(String) msg.obj;
			mList=JsonUtil.BookListFromJson(str);
			mAdapter=new BookListAdapter(getApplicationContext(), mList);
			mListView.setAdapter(mAdapter);
		};
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.book_list_seller);
		mListView=(ListView) findViewById(R.id.lv_book_list_seller);
		mListView.setOnItemClickListener(this);
		String url=Constan.BASE_URL+"BookListSellerServlet";
		new HttpClientPostThread(url, mHandler, "2").start();;
		
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Intent intent=new Intent();
		Gson gson =new Gson();
		String jsondata=gson.toJson(mList.get(position));
		if(mList.get(position).getBookStatus()<=2){
			intent.setClass(getApplicationContext(), BookConfirmActivity.class);
			intent.putExtra("book", jsondata);
			startActivityForResult(intent, 1000);
		}
		
	}
	
	public void IbBack(View v){
		finish();
	}

}
